package com.goldze.mvvmhabit.ui.rvgroup;


import com.goldze.mvvmhabit.widght.expand.ExpandableViewModel;

import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableList;

/**
 * create om  2020/11/16.
 * Created by  gaoxuge
 * email android_gaoxuge@163.com
 * 功能描述
 */
public class ExpandChildViewModel<T extends ExpandableViewModel> implements ExpandableViewModel {
    private ExpandParentViewModel vm;
    //给RecyclerView添加ObservableList
    public ObservableList<ExpandableViewModel> mDataList = new ObservableArrayList<>();
    public final long mIndex;
    public ExpandChildViewModel(ExpandParentViewModel viewModel,long index, String t) {
        this.vm = viewModel;
        mIndex = index;

        text.set(t);


    }

    public void initData(){
        mDataList.clear();
        for (int i = 0; i < 5; i++) {
            String text = "我是第" + i + "条";
            ExpandChildViewModel item = new ExpandChildViewModel( vm, i, text);
            mDataList.add(item);
        }
    }
    public ObservableField<String> text = new ObservableField<>("");
    @Override
    public ExpandableViewModel getChild(int position) {
        return mDataList.get(position);
    }

    @Override
    public ObservableList<ExpandableViewModel> getItems() {
        return mDataList;
    }

    @Override
    public int getChildCount() {
        return mDataList.size();
    }

    @Override
    public long getId() {
        return mIndex;
    }

    @Override
    public long getChildId(int position) {
        return mDataList.get(position).getId();
    }
}
